from django.forms import ModelForm
from django.forms.extras.widgets import SelectDateWidget
from DB_WORK.HIS.models import *
from datetime import datetime as dt

class PatientForm(ModelForm):
	def save(self, p_id):
		pi = Patient_Info(patient_id = p_id, **self.cleaned_data)
		pi.save()
	class Meta:
		model = Patient_Info
		exclude = ('patient_id', )
		
class DoctorForm(ModelForm):
	def save(self, d_id):
		di = Doctor_Info(doctor_id = d_id, **self.cleaned_data)
		di.save()
	class Meta:
		model = Doctor_Info
		exclude = ('doctor_id')
		
class DiagnosisForm(ModelForm):		
	def save(self, d_id):
		di = Diagnosis(doctor_id = Doctor_Info.objects.get(doctor_id=d_id), date_time = dt.now(), **self.cleaned_data)
		di.save()
	class Meta:
		model = Diagnosis
		exclude = ('doctor_id', 'date_time',)
		
class AppointmentForm(ModelForm):
	def __init__(self, *args, **kwargs):
		super(AppointmentForm, self).__init__(*args, **kwargs)
		self.fields['date_time'].widget = SelectDateWidget()
	def save(self, d_id):
		di = Appointment(doctor_id = Doctor_Info.objects.get(doctor_id=d_id), **self.cleaned_data)
		di.save()
	class Meta:
		model = Appointment
		exclude = ('doctor_id', )